package model.dao;

import java.sql.ResultSet;
import java.util.ArrayList;

import controller.util.ControllerHelper;

import model.pojo.Paypal;
import model.util.DataHelper;

public class PaypalDAO {

	//lay danh sách loại sản phẩm
		public static Paypal LayThongTinPaypal()
		{
			Paypal pp = new Paypal();
			
			DataHelper helper = new DataHelper();
	        try
	        {
	            helper.open();
	            ArrayList<Object> para = new ArrayList<Object>();
	            ResultSet result = helper.executeProcedure("{call sp_SelectPaypal()}", para);
	            if(result.next())
	            {
	            	pp.setIDPaypal(result.getInt("ID"));
	            	pp.setAPIPassword(result.getString("APIPassword"));
	            	pp.setAPISignature(result.getString("APISignature"));
	            	pp.setAPIUserName(result.getString("APIUserName"));
	            	pp.setTyGia(result.getFloat("TyGiaUSD"));
	                
	            }
	            
	        }catch(Exception ex)
	        {
	            //System.out.println(ex.getMessage());
	        }
	        finally
	        {
	            helper.close();
	        }
	  
			return pp;
		}
	//cap nhat paypal
		public static boolean CapNhat(Paypal pp)
		{
			boolean kq = false;
			DataHelper helper = new DataHelper();
	        try
	        {
	            helper.open();
	            ArrayList<Object> para = new ArrayList<Object>();
	            para.add(pp.getIDPaypal());
	            para.add(pp.getAPIUserName());
	            para.add(pp.getAPIPassword());
	            para.add(pp.getAPISignature());
	            para.add(pp.getTyGia());
	            String sp = ControllerHelper.getStoreProcedureString("CapNhatPaypal");
	            int kqUP = helper.executeInsProcedure(sp, para);
	            if(kqUP>0)
	            {
	            	kq=true;
	            }	            
	            
	        }catch(Exception ex)
	        {
	            //System.out.println(ex.getMessage());
	        }
	        finally
	        {
	            helper.close();
	        }
			return kq;
		}
}
